package com.niit.listener;

import java.awt.event.MouseEvent;
import java.sql.Timestamp;

import com.niit.dao.BookDao;
import com.niit.dao.impl.BookDaoImpl;
import com.niit.entity.Book;
import com.niit.view.MainView;

public class UpdateListener extends MyMouseListenerAdapter {
	private BookDao bookDao;
	private Book b;

	
	public Book getB() {
		return b;
	}

	public UpdateListener(Book b) {
		this.bookDao = new BookDaoImpl();
		this.b = b;
	}

	@Override
	public void mouseClicked(MouseEvent e) {
		System.out.println("点击提交后");
		Book b = view.getBook();
		String bookName = view.getBookNameTextField().getText();
		String bookPrice = view.getBookPriceTextField().getText();
		String bookAuthor = view.getBookAuthorTextField().getText();
		String bookPublisher = view.getBookPublisherTextField().getText();
		Book book = new Book(b.getId(),Double.parseDouble(bookPrice), bookName, bookAuthor, bookPublisher,new Timestamp(System.currentTimeMillis()));
		bookDao.update(book);
		new MainView(null);
		view.dispose();
	}
}
